#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 110;

int n, c;
int cnt[N];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        memset(cnt, 0, sizeof cnt);
        cin >> n >> c;

        for(int i = 0, x; i < n; i ++){
            cin >> x;
            cnt[x] ++;
        }

        int res = 0;
        for(int i = 1; i <= 100; i ++){
            if(cnt[i] > c) res += c;
            else res += cnt[i];
        }

        cout << res << endl;
    }



    return 0;
}